import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;

import javax.swing.JPanel;

class Map extends JPanel{
	private static final long serialVersionUID = 1L;

	protected Image block,back,black;
	protected int map[][];
	protected int score = 0;

	Block b = new Block();
	CreateMap m = new CreateMap();
	FallBlock fall;
	AddBlock add;
	SwapBlock swap;
	boolean isExist_7 = false;

	public void paint(Graphics g) {
		map = m.map; //CreateMapの情報がここで入る
		back = getToolkit().getImage("img/back5.jpg");
		g.drawImage(back, 0, 0, this);
		black = getToolkit().getImage("img/black.png");
		//g.setColor(Color.BLACK);
		//g.fillRect(0, 0, 500, 500);
		for (int i = 0; i <= 7; i++) {
			for (int j = 0; j <= 7; j++) {
				block = b.randomize(map[i][j]);
				g.drawImage(block, 50 * (i + 1), 50 * (j + 1), this);
			}
		}
		g.setFont(new Font("Consolas", Font.ITALIC, 22));
		g.setColor(Color.YELLOW);
		g.drawString("Score: " + Score.score, 290, 30);
		
		g.setFont(new Font("Consolas", Font.ITALIC, 30));
		g.setColor(Color.RED);
		g.drawString("Time: " + Time.lefttime, 20, 30);
	}


	public void swapBlock(int i, int j) {
		swap = new SwapBlock();
		swap.swapBlock(map,i, j);
		repaint();
	}
/*
	public void destroyBlock2(Destroy block){
		fall = new FallBlock();
		add = new AddBlock();
		while(block.isExistance() == true){
			destroy(block.getDestroyBlock());
		}
		fall.fallBlock(map);
		add.addBlock(map);
		repaint();
	}

	 public int destroy(DestroyBlock block){
		 map[block.getDestroyLoation_y()][block.getDestroyLoation_x()] = 7;
		 repaint();
		 stop(1000);
		 return block.getDestroyLoation_y();
	}

*/
	public void stop(int sleeptime){
		try {
			Thread.sleep(sleeptime);	// ０.５秒間停止
		} catch (InterruptedException e) {
			System.out.println(e);
		}
	}

}